﻿@model CityDTO[]
@{
    ViewBag.Title = "AddNew";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<section class="layui-larry-box">
    <div class="larry-personal">
        <header class="larry-personal-tit">
            <span>添加小区</span>
        </header><!-- /header -->
        <div class="larry-personal-body clearfix">
            <form class="layui-form col-lg-5" id="form">
                <div class="layui-form-item">
                    <label class="layui-form-label">区名</label>
                    <div class="layui-input-block">
                        <input type="text" name="Name" lay-verify="required" autocomplete="off" class="layui-input" placeholder="请输入小区名">
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">该区所属市</label>
                        <div class="layui-input-inline">
                            <select name="CityId" class="newsLook" lay-filter="browseLook">
                                @foreach (var city in Model)
                                {
                                    <option value="@city.Id">@city.Name</option>
                                }
                            </select>
                        </div>

                    </div>
                </div>



                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</section>

@section FooterScript{
    <script type="text/javascript">

        var appConfig = {};

        layui.use(['form'], function () {
            var form = layui.form();
            form.on("submit(demo1)", function (data) {
                var json = $("#form").serialize();
                $.ajax({
                    url: "/Area/AddNew",
                    type: "post",
                    dataType: "json",
                    data: json,
                    success: function (res) {
                        if (res.status == "error") {
                            layer.msg(res.errorMsg, { icon: 2, time: 2000 });
                        }
                        else if (res.status == "ok") {
                            parent.location.reload();
                        } else {
                            layer.msg("错误", { icon: 2, time: 1500 });
                        }
                    },
                    error: function () {
                        layer.msg("请求出错");
                    }
                });
                return false;
            })
        })
    </script>
}

